package com.huanletao.proxy.cglib;

import org.apache.commons.lang3.StringUtils;

import java.lang.reflect.Method;

/**
 * <p>
 * </p>
 * package: com.huanletao.proxy.cglib
 * description:
 * className: MethodNameAdvisor
 * author:  踏雪无痕
 * copyright: Copyright (c) 2022/8/26 22:27
 * since: 1.0.0
 */
public class MethodNameAdvisor implements Advisor {

    private Interceptor interceptor;

    private String methodNamePrefix;

    public MethodNameAdvisor() {
    }

    public MethodNameAdvisor(Interceptor interceptor){
        this.interceptor = interceptor;
    }

    @Override
    public Interceptor getInterceptor() {
        return interceptor;
    }


    public void setInterceptor(Interceptor interceptor) {
        this.interceptor = interceptor;
    }

    @Override
    public boolean matches(Method method, Class<?> targetClass) {
        return  StringUtils.startsWith(method.getName(), methodNamePrefix);
    }

    public String getMethodNamePrefix() {
        return methodNamePrefix;
    }

    public void setMethodNamePrefix(String methodNamePrefix) {
        this.methodNamePrefix = methodNamePrefix;
    }
}
